<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>登录</title>
    <script type="text/javascript" src="https://cdn.staticfile.org/jquery/1.10.2/jquery.min.js"></script>
</head>
<body>
<h1>登录</h1>
    用户名:<input type="text" id="username" />
    密  码:<input type="password" id="pwd" />
    <button id="aa">登录</button>
</body>
<script type="text/javascript">
    $(document).ready(function(){
        $("button#aa").click(function(){
            //var jsonObj = {id: $("#id").val(),name:"abcd",age:"123"};
            $.ajax({
                async : false,
                url: "/auth",
                data:{
                    "username":$("#username").val(),
                    "pwd":$("#pwd").val()
                },
                //data:JSON.stringify(jsonObj),  传入json数据
                type: "POST",
                dataType:"json",//返回数据类型
                //headers:{"Content-Type":"application/json"},  传入json数据时需设置请求头
                success:function(data){
                    alert(data.name);
                },
                error:function(err){
                    alert('连接失败'+err);
                }
            });
        });
    });
</script>
</html>